package com.ideaaedi.zoo.diy.feature.config.api;

import com.ideaaedi.zoo.diy.feature.config.api.logger.LogbackLoggerLevelChanger;
import com.ideaaedi.zoo.diy.feature.config.api.properties.AppStartedLoggerLevelProperties;
import com.ideaaedi.zoo.diy.feature.config.api.properties.ZooConfigApiDIYGuideProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync;

/**
 * config 自动配置
 */
@EnableAsync
@EnableConfigurationProperties({AppStartedLoggerLevelProperties.class, ZooConfigApiDIYGuideProperties.class})
@ConditionalOnProperty(value = ZooConfigApiAutoConfiguration.ENABLE, havingValue = "true", matchIfMissing = true)
public class ZooConfigApiAutoConfiguration {
    
    public static final String ENABLE = "zoo.switch.feature-config-api.enable";
    
    @Bean
    @ConditionalOnClass(ch.qos.logback.classic.Level.class)
    public LogbackLoggerLevelChanger logbackLoggerLevelChanger(AppStartedLoggerLevelProperties appStartedLoggerLevelProperties) {
        return new LogbackLoggerLevelChanger(appStartedLoggerLevelProperties);
    }
}